package com.base.sort;

import java.util.Arrays;

/**
 *
 */
public class Bubble {
    public static void sort(int[] a) {
        //外层循环控制比较的次数
        for (int i = 0; i < a.length - 1; i++) {
            //内层循环控制到达位置
            for (int j = 0; j < a.length - i - 1; j++) {
                //前面的元素比后面大就交换
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
    }


    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,55,79,6,10};

        sort(array);

//        System.out.println("array = " + Arrays.asList(array).toString());
        for (int i : array) {
            System.out.print(i);
            System.out.println("\t");
        }
    }
}
